package liaotian;

import java.io.ObjectInputStream;
import java.net.Socket;

import javax.swing.JTextArea;

public class ReceiveThread implements Runnable{
	private Socket socket;
	private JTextArea textArea;
	public ReceiveThread(Socket socket, JTextArea textArea) {
		this.socket = socket;
		this.textArea = textArea;
	}
	
	@Override
	public void run() {
		try {			
			while(true){
				ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
				String o=(String)ois.readObject();
				textArea.append(o+"\n");	
				textArea.setCaretPosition(textArea.getText().length());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
